<template>
  <PCard
    class="iitd-con"
    :isCardBorder="false"
    :shadow="'never'"
    :isHeadBottomBorder="true"
    :bodyStyle="{ width: '100%' }"
  >
    <div slot="header" class="iitd-title">
      <span>业务支出凭证</span>
      <a-button icon="plus" v-if="btnShow" style="float: right" @click="addData">新 增</a-button>
      <a-button
        v-show="btnConfig.show"
        :disabled="btnConfig.disabled"
        @click="btnEvent"
        type="primary"
        block
        style="width: 150px; float: right;"
      >
        {{ btnConfig.label }}</a-button
      >
    </div>
    <div class="iitd-list">
      <div class="iitd-item">
        <a-table :columns="columns" :data-source="data" bordered :scroll="{ y: 400 }">
          <template slot="dataNum" slot-scope="text, record">
            <Iitd :dataKey="'dataNum'" type="1" :dataList="record"></Iitd>
          </template>
          <template slot="dataDec" slot-scope="text, record">
            <Iitd :dataKey="'dataDec'" type="2" :dataList="record"></Iitd>
          </template>

          <template slot="amount" slot-scope="text, record">
            <Iitd :dataKey="'amount'" type="3" :dataList="record"></Iitd>
          </template>
          <template slot="action" slot-scope="indent, record, index, expanded">
            <!-- {{record }} -->
            <!-- {{index }}
            {{indent }} -->
            <!-- {{expanded }} -->
            <Iitd
              :dataKey="'action'"
              type="4"
              :status="dataStatus"
              :dataList="record"
              :rowNum="index"
              :showFileEvent="showFileEvent"
            ></Iitd>
          </template>
          <template slot="footer" slot-scope="currentPageData">
            <div class="table-row">
              <div class="table-cell">总计</div>
              <div class="table-cell"></div>
              <div class="table-cell"></div>
              <div class="table-cell">{{ getSum(currentPageData) }}</div>
              <div class="table-cell"></div>
            </div>
          </template>
        </a-table>
        <!-- <previewShow v-bind="PreviewShowConfig" :event="modalHidden"></previewShow> -->
        <p-PreviewShow v-bind="PreviewShowConfig" :event="modalHidden"></p-PreviewShow>
      </div>
      <div class="iitd-item group" v-if="groupData.show">
        <div class="group-title">本季度税务申报</div>
        <a-table
          :columns="groupData.tdaq.columns"
          :data-source="groupData.tdaq.data"
          bordered
          :scroll="{ y: 400 }"
          class="group-table"
        >
          <template slot="title" slot-scope="currentPageData"> 本季度申报总额 </template>
          <template slot="footer" slot-scope="currentPageData">
            <div class="table-row">
              <div class="table-cell">本季度收入合计</div>
              <div class="table-cell"></div>
              <div class="table-cell"></div>
              <div class="table-cell"></div>
              <div class="table-cell">{{bjdsrhj}}</div>
            </div>
          </template>
        </a-table>
        <a-table
          :columns="groupData.ttpq.columns"
          :data-source="groupData.ttpq.data"
          bordered
          :scroll="{ y: 400 }"
          class="group-table"
        >
          <template slot="title" slot-scope="currentPageData"> 本季度纳税总额 </template>
          <template slot="footer" slot-scope="currentPageData">
            <div class="table-row">
              <div class="table-cell">税费合计</div>
              <div class="table-cell"></div>
              <div class="table-cell"></div>
              <div class="table-cell"></div>
              <div class="table-cell"></div>
              <div class="table-cell">{{sfhj}}</div>
            </div>
          </template>
        </a-table>
        <!-- <div class="itd-con"><span>个税费差额：</span><span>{{ groupData.itd }}</span></div> -->
      </div>
      <div class="iitd-item">
        <a-button
          type="primary"
          v-if="btnShow"
          :loading="btnLoading"
          :disabled="btnDisabled"
          icon="check"
          @click="saveData"
          >提 交</a-button
        >
      </div>
    </div>
    <a-modal
      :title="winConfig.title"
      :visible="winConfig.visible"
      :maskClosable="false"
      dialogClass="winModal"
      @ok="handleOk"
      @cancel="handleCancel"
    >
      <div class="winModal-body">
        <PageForm
          ref="addIitdForm"
          formKey="kkkkkkk"
          :formConfig="formConfig"
          :itemList="itemList"
          :formEvent="defaultFormEvent"
        ></PageForm>
        <div class="file-con">
          <div class="file-item xx">选择要上传的凭证</div>
          <div class="file-item">
            <UpLoadFile ref="iitd" :config="sfzConfig" :fileChangeEvent="fileChangeEvent"></UpLoadFile>
          </div>
        </div>
      </div>
    </a-modal>
  </PCard>
</template>

<script>
import getDataForDB from '@/api/qsbBusinessManagement'
import getDataForDB1 from '@/api/MoveLayout'
import { conversionBranch, conversionElement } from '@/utils/util'
import Iitd from './iitd.vue'
// import PreviewShow from '@/views/common/filePreview.vue'
const columns = [
  {
    title: '类目',
    className: 'column-title',
    dataIndex: 'name',
    scopedSlots: { customRender: 'name' },
  },
  {
    title: '项目编号',
    className: 'column-title',
    dataIndex: 'dataNum',
    scopedSlots: { customRender: 'dataNum' },
  },
  {
    title: '凭证描述',
    className: 'column-title',
    dataIndex: 'dataDec',
    scopedSlots: { customRender: 'dataDec' },
  },
  {
    title: '金额',
    className: 'column-title',
    dataIndex: 'amount',
    scopedSlots: { customRender: 'amount' },
  },
  {
    title: '操作',
    className: 'column-title',
    dataIndex: 'action',
    scopedSlots: { customRender: 'action' },
  },
]

const data = [
  // {
  //   key: '1',
  //   name: '业务成本费用',
  //   dataNum: '',
  //   dataDec: '',
  //   amount: '',
  //   dataList: [
  //     // {  key: '1',name: 'John Brown1',  dataNum: '1', state:'未上传凭证',  dataDec: '11111111111111', amount:'1' },
  //     // {  key: '2',name: 'John Brown2',  dataNum: '2', state:'已上传凭证',  dataDec: '22222222222222', amount:'2' },
  //     // {  key: '3',name: 'John Brown3',  dataNum: '3', state:'已提交',  dataDec: '33333333333333', amount:'3' },
  //     // {  key: '4',name: 'John Brown3',  dataNum: '4', state:'已审批',  dataDec: '44444444444444', amount:'4' },
  //   ]
  // },
  // {
  //   key: '2',
  //   name: '业务招待费',
  //   dataNum: '',
  //   dataDec: '',
  //   amount: '',
  //   dataList: [
  //     // {  key: '1',name: 'John Brown1', fileList:[],  dataNum: '1', state:'未上传凭证',  dataDec: '11111111111111', amount:'1' },
  //     // {  key: '2',name: 'John Brown2',  dataNum: '2', state:'已上传凭证',  dataDec: '22222222222222', amount:'2' },
  //     // {  key: '3',name: 'John Brown3',  dataNum: '3', state:'已提交',  dataDec: '33333333333333', amount:'3' },
  //     // {  key: '4',name: 'John Brown3',  dataNum: '4', state:'已审批',  dataDec: '44444444444444', amount:'4' },
  //   ]
  // },
  // {
  //   key: '3',
  //   name: '职工福利费',
  //   dataNum: '',
  //   dataDec: '',
  //   amount: '',
  //   dataList: [
  //     // {  key: '1',  dataNum: '1', state:'未上传凭证',  dataDec: '11111111111111', amount:'1' },
  //     // {  key: '2',  dataNum: '2', state:'已上传凭证',  dataDec: '22222222222222', amount:'2' },
  //     // {  key: '3',  dataNum: '3', state:'已提交',  dataDec: '33333333333333', amount:'3' },
  //     // {  key: '4',  dataNum: '4', state:'已审批',  dataDec: '44444444444444', amount:'4' },
  //   ]
  // },
  // {
  //   key: '4',
  //   name: '工会经费',
  //   dataNum: '',
  //   dataDec: '',
  //   amount: '',
  //   dataList: [
  //     // {  key: '1',  dataNum: '1', state:'未上传凭证',  dataDec: '11111111111111', amount:'1' },
  //     // {  key: '2',  dataNum: '2', state:'已上传凭证',  dataDec: '22222222222222', amount:'2' },
  //     // {  key: '3',  dataNum: '3', state:'已提交',  dataDec: '33333333333333', amount:'3' },
  //     // {  key: '4',  dataNum: '4', state:'已审批',  dataDec: '44444444444444', amount:'4' },
  //   ]
  // },
  // {
  //   key: '5',
  //   name: '职工教育经费',
  //   dataNum: '',
  //   dataDec: '',
  //   amount: '',
  //   dataList: [
  //     // {  key: '1',  dataNum: '1', state:'未上传凭证',  dataDec: '11111111111111', amount:'1' },
  //     // {  key: '2',  dataNum: '2', state:'已上传凭证',  dataDec: '22222222222222', amount:'2' },
  //     // {  key: '3',  dataNum: '3', state:'已提交',  dataDec: '33333333333333', amount:'3' },
  //     // {  key: '4',  dataNum: '4', state:'已审批',  dataDec: '44444444444444', amount:'4' },
  //   ]
  // },
]

const pageFormConfig_ = {
  columnCount: 4,
  layout: 'horizontal',
  labelAlign: 'left',
  labelCol: { span: 6 },
  wrapperCol: { span: 18 },
  rowAttr: {
    //  type:'',justify:'',gutter:'',align:''
  },
  celAttr: {
    // flex,offset,order,pull,push,span,xxl...
  },
}
const formItemAttr_ = { labelCol: { xxl: 5, xl: 12 }, wrapperCol: { xxl: 19, xl: 12 } }

const typeObj = {
  1: '业务成本费用',
  2: '业务招待费1',
  3: '职工福利费1',
  4: '工会经费1',
  5: '职工教育经费1',
  6: '工资薪金支出',
  7: '社保及公积金支出',
  8: '工会经费',
  9: '职工福利费',
  10: '职工教育经费',
  11: '业务招待费',
  12: '广告费及业务宣传费',
  13: '行政性收费',
  14: '固定资产租赁费用',
  15: '折旧费',
  16: '公益性捐赠支出',
  业务成本费用: '1',
  业务招待费1: '2',
  职工福利费1: '3',
  工会经费1: '4',
  职工教育经费1: '5',
  工资薪金支出: '6',
  社保及公积金支出: '7',
  工会经费: '8',
  职工福利费: '9',
  职工教育经费: '10',
  业务招待费: '11',
  广告费及业务宣传费: '12',
  行政性收费: '13',
  固定资产租赁费用: '14',
  折旧费: '15',
  公益性捐赠支出: '16',
}

const selectOption = (disabled = true) => {
  const resArr = [
    // { enName: '1', cnName: '业务成本费用' },
    // { enName: '2', cnName: '业务招待费1' },
    // { enName: '3', cnName: '职工福利费1' },
    // { enName: '4', cnName: '工会经费1' },
    // { enName: '5', cnName: '职工教育经费1' },
    { disabled: false, enName: '6', cnName: '工资薪金支出' },
    { disabled: disabled, enName: '7', cnName: '社保及公积金支出' },
    { disabled: disabled, enName: '8', cnName: '工会经费' },
    { disabled: disabled, enName: '9', cnName: '职工福利费' },
    { disabled: disabled, enName: '10', cnName: '职工教育经费' },

    { disabled: false, enName: '11', cnName: '业务招待费' },
    { disabled: false, enName: '12', cnName: '广告费及业务宣传费' },
    { disabled: false, enName: '13', cnName: '行政性收费' },
    { disabled: false, enName: '14', cnName: '固定资产租赁费用' },
    { disabled: false, enName: '15', cnName: '折旧费' },
    { disabled: false, enName: '16', cnName: '公益性捐赠支出' },
  ]
  return resArr
}

const handleRegMoneyCheck = (rule, value, callback) => {
  var reg = /^\d+(?=\.{0,1}\d+$|$)/
  if (value != undefined && !reg.test(value)) {
    callback(new Error('请输入大于0的数字'))
  } else {
    callback()
  }
}

const columns_tdaq = [
  {
    title: '类别',
    align: 'center',
    dataIndex: 'classification',
  },
  {
    title: '增值税发票',
    align: 'center',
    colSpan: 2,
    dataIndex: 'ValueAddedTaxInvoice',
  },
  {
    title: '增值税发票',
    align: 'center',
    colSpan: 0,
    dataIndex: 'ValueAddedTaxInvoice1',
  },
  {
    title: '增值税普票',
    align: 'center',
    dataIndex: 'VATGeneralInvoice',
  },
  {
    title: '未开票收入',
    align: 'center',
    dataIndex: 'unbilledRevenue',
  },
]
const columns_ttpq = [
  {
    title: '类别',
    align: 'center',
    dataIndex: 'classification',
  },
  {
    title: '增值税',
    align: 'center',
    dataIndex: 'valueAddedTax',
  },
  {
    title: '附加税',
    align: 'center',
    dataIndex: 'additionalTax',
  },
  {
    title: '个人经营所得税',
    align: 'center',
    dataIndex: 'personalTaxReal',
  },
  {
    title: '实缴附加税',
    align: 'center',
    dataIndex: 'additionalTaxReal2',
  },
  {
    title: '税费差额',
    align: 'center',
    dataIndex: 'differenceAmount',
  },
]

export default {
  name: 'sipiIndividualIncomeTaxDeclaration',
  components: { Iitd },
  props: {
    pageInfo: { type: Object },
  },
  data() {
    return {
      columns,
      data,
      groupData: {
        show: true,

        /**
         * 本季度申报总额
         */
        tdaq: {
          columns: columns_tdaq,
          data: [
            // { classification: '1', ValueAddedTaxInvoice: '2', ValueAddedTaxInvoice1: '3', VATGeneralInvoice: '4', UnbilledRevenue: '5' }
            {
              classification: '税率',
              ValueAddedTaxInvoice: '--',
              ValueAddedTaxInvoice1: '--',
              VATGeneralInvoice: '--',
              unbilledRevenue: '1%',
            },
            {
              classification: '收入金额',
              ValueAddedTaxInvoice: '--',
              ValueAddedTaxInvoice1: '--',
              VATGeneralInvoice: '--',
              unbilledRevenue: '',
            },
          ],
        },
        /**
         * 本季度纳税总额
         */
        ttpq: {
          columns: columns_ttpq,
          data: [
            // { classification: '1', valueAddedTax: '2', additionalTax: '3', personalBusinessIncomeTax: '4' }
            {
              classification: '税费金额',
              valueAddedTax: '--',
              additionalTax: '--',
              personalTaxReal: '--',
              additionalTaxReal2: '--',
              differenceAmount: '--',
            },
          ],
        },
        // 个税费差额：
        itd: '123元',
        // 本季度收入合计  当接口有时，使用接口的
        tdaqSum:'',
        // 税费合计
        sfhj: '--',
      },
      btnConfig: {
        disabled: false,
        label: '',
        state: 0,
        show: false,
      },
      btnLoading: false,
      btnDisabled: false,
      // 用于控制 新增 提交 按钮 是否显示
      btnShow: true,
      sfzConfig: {
        dir: '/qsb/idCard/', // 上传文件的地址
        required: true, // 文件上传必填校验 默认为false 不校验   当值为true时进行强制校验
        // multiple: false, // 优先级高于isTwo  开启多文件上传  默认值为false   当值为true时表示开启对文件上传，同时 isTwo 和 upLoadCardListConfig 失效
        // isTwo: true, // 是否开启两个卡片上传 默认为false  表示只启用单个卡片单文件上传   true 表示开启两个卡片的单文件上传
        showCardList: ['card1'],
        upLoadCardListConfig: [{ type: '1', tips: '上传凭证', fileInfo: { name: '', url: '' } }], // 此项最多可以传两组值 {type:'1',tips:'身份证人像面',backgroundPic:''},
        fielConfig: {
          type: '凭证', // 允许上传的文件类型 当为空时表示不限制  默认为空   可供选择类型： 图片  文档  压缩包  发票
          size: 1, // 允许上传的文件个数  默认值为1
          singleFileSize: 50, //上传的单个文件大小 单位为 MB  默认值为1
        },
      },
      winConfig: {
        visible: false,
        title: '新增支出凭证',
      },
      formConfig: pageFormConfig_,
      itemList: [
        {
          enName: 'name',
          cnName: '类目',
          type: 'select',
          value: '',
          isRequire: true,
          optionList: selectOption(),
          itemAttr: { placeholder: '请选择类目', allowClear: true },
          formItemAttr: formItemAttr_,
        },
        {
          enName: 'dataDec',
          cnName: '凭证描述',
          type: 'input',
          value: '',
          isRequire: true,
          itemAttr: { placeholder: '请输入凭证描述', allowClear: true },
          formItemAttr: formItemAttr_,
        },
        {
          enName: 'amount',
          cnName: '金额',
          type: 'input',
          value: '',
          isRequire: [
            { required: true, message: `金额 值不能为空` },
            {
              validator: (rule, value, callback) => {
                handleRegMoneyCheck(rule, value, callback)
              },
            },
          ],
          itemAttr: { placeholder: '请输入金额', allowClear: true },
          formItemAttr: formItemAttr_,
        },
      ],
      checkRes: [false, false],
      fileList: [],
      PreviewShowConfig: {
        config: { title: '合同预览', visible: false },
        url: '',
        suffix: '',
        name: '',
      },
      dataStatus: '',

      apiList: {
        178: ['本季度申报总额'],
        177: ['本季度申报总额177'],
        // 178: ['查询企业信息及个税申报详情', '本季度申报总额', '客户确认未开票收入'],
        // 177: ['查询企业信息及个税申报详情177', '本季度申报总额177', '客户确认未开票收入177']
      },
      // 查账征收  178    核定征收 177
      pageType: 178,
    }
  },
  watch: {
    pageInfo: {
      handler(val) {
        if (Object.prototype.toString.call(val) === '[object Object]') {
          const { dbData } = val
          const status = (dbData.taxDeclarationEntVo && dbData.taxDeclarationEntVo.status) || dbData.status
          // 全部 5待提交 10待审核 20审核驳回 25资料待完善 26待认证 30待支付 33待退款 40支付失败 50办理中 60办理完成 70已取消 80办理失败
          if (status === 5) {
            this.btnShow = true
          } else {
            this.btnShow = false
          }
          //  5待提交 10待审核 20审核驳回 23待发布 24待确认 25资料待完善 30待支付 40支付失败 50办理中 60办理完成 70已取消 80办理失败
          if (this.pageInfo.dbData.status == 24) {
            this.btnConfig.show = true
            this.btnConfig.label = '确认申报内容'
            // 确认之后  直接隐藏 按钮
            this.btnConfig.state = 2
            // this.supplementaryTaxConfig.label = '您需要补缴税费：'
          } else if (this.pageInfo.dbData.status == 30) {
            // this.pageInfo.dbData.status == 30
            this.btnConfig.show = true
            this.btnConfig.label = '支付税费差额'
            // 确认之后  直接隐藏 按钮
            this.btnConfig.state = 1
            this.getPaidAmount(this.pageInfo.dbData.orderNo)
          } else if (this.pageInfo.dbData.status == 26) {
            // this.pageInfo.dbData.status == 30
            this.btnConfig.show = true
            this.btnConfig.label = '客户认证'
            // 确认之后  直接隐藏 按钮
            this.btnConfig.state = 4
            this.getPaidAmount(this.pageInfo.dbData.orderNo)
          } else {
            this.btnConfig.show = false
          }


          // this.btnShow = true
          this.dataStatus = status
          this.setTableData(dbData)
          // 待确认 26  待认证 26  待处理 10  退款中 33   显示 本季度税务申报
          const showStatus = [26, 10, 33, 60]
          if (showStatus.indexOf(status) >= 0) {
            this.groupData.show = true
            this.setTTPQData(dbData)
            this.getPageDataForAPI(dbData.flowNo)
          } else {
            this.groupData.show = false
          }
        }
      },
      deep: true,
      immediate: true,
    },
    checkRes: {
      handler(val) {
        if (Object.prototype.toString.call(val) === '[object Array]' && val.indexOf(false) < 0) {
          this.winConfig.visible = false
        }
      },
      deep: true,
      immediate: true,
    },
    data: {
      handler(val) {
        if (Object.prototype.toString.call(val) === '[object Array]' && val.length > 0) {
          let temp = false
          val.forEach((item) => {
            const { name } = item
            if (name == '工资薪金支出') {
              temp = true
            }
          })
          if (temp === true) {
            this.itemList[0].optionList = selectOption(false)
          } else {
            this.itemList[0].optionList = selectOption(true)
          }
        }
      },
      deep: true,
      immediate: true,
    },
  },
  computed: {
     // 本季度收入合计
     bjdsrhj() {
      const temp = this.groupData.tdaq.data[1]
      const sum_ = this.groupData.tdaqSum;
      return sum_ || this.getTableRowCalue(temp, ['classification']).toFixed(2)
    },
    // 税费合计
    sfhj() {
      const temp = this.groupData.ttpq.data[0]
      return this.getTableRowCalue(temp, ['classification']).toFixed(2)
    }
  },
  methods: {
    getTableRowCalue(rowObj, notKey = []) {
      let sum = 0
      Object.keys(rowObj).forEach(key => {
        if (notKey.indexOf(key) >= 0) {
          return false
        }
        try {
          const value = Number(rowObj[key])
          sum += isNaN(value) ? 0 : value
        } catch (error) {}
      })
      return sum
    },
    fen2yuan(val) {
      return conversionElement(val)
    },
    getSum(data) {
      // console.log('1111111111111', data);
      let tempSum = 0
      data.forEach((item) => {
        item.dataList.forEach((item_) => {
          const { amount } = item_
          tempSum += ~~amount
        })
      })
      return tempSum
    },
    getPaidAmount(orderNo) {
      // getDataForDB('根据订单编号获取待支付金额', { orderNo }).then(res => {
      //   const { success, result } = res
      //   if (success) {
      //     this.supplementaryTaxConfig.show = true
      //     this.supplementaryTaxConfig.amount = this.fen2yuan(result.amount)
      //   }
      // })
    },
    setDefaultData() {
      this.data.forEach((item) => {
        item.dataList = []
      })
    },
    setTableData(dbData) {
      this.setDefaultData()
      const { taxDeclarationEntVo, details } = dbData
      // const name2RowNum = { "1": 0, "2": 1, "3": 2, "4": 3, "5": 4 }
      const addArr = (dataArr) => {
        const tempArr = []
        const tempObj = {}
        dataArr.forEach((item, index) => {
          const { category } = item
          let name = typeObj[category]
          if (tempObj[name]) {
            tempObj[name].push({
              fileList: [{ url: item.url }],
              dataNum: item.itemCode,
              state: '已上传凭证',
              dataDec: item.desc,
              amount: conversionElement(item.amount),
            })
          } else {
            tempObj[name] = [
              {
                fileList: [{ url: item.url }],
                dataNum: item.itemCode,
                state: '已上传凭证',
                dataDec: item.desc,
                amount: conversionElement(item.amount),
              },
            ]
          }
        })
        let index = 1
        for (const key in tempObj) {
          if (Object.hasOwnProperty.call(tempObj, key)) {
            const element = tempObj[key]
            tempArr.push({
              key: index,
              name: key,
              dataNum: '',
              dataDec: '',
              amount: '',
              dataList: element,
            })
            index++
          }
        }
        return tempArr
      }
      // details
      if (details && details.length > 0) {
        // details.forEach(item => {
        //   const { category } = item
        //   const rowNum = name2RowNum[category]
        //   this.data[rowNum].dataList.push({ fileList: [{ url: item.url }], dataNum: item.itemCode, state: '已上传凭证', dataDec: item.desc, amount: conversionElement(item.amount) })
        // })
        this.data = addArr(details)
      }
      if (taxDeclarationEntVo && taxDeclarationEntVo.details && taxDeclarationEntVo.details.length > 0) {
        // taxDeclarationEntVo.details.forEach(item => {
        //   const { category } = item
        //   const rowNum = name2RowNum[category]
        //   this.data[rowNum].dataList.push({ fileList: [{ url: item.url }], dataNum: item.itemCode, state: '已上传凭证', dataDec: item.desc, amount: conversionElement(item.amount) })
        //   //#region  接口字段说明
        //   // amount:222
        //   // category:1
        //   // createBy:"不是事有限公司"
        //   // createById:208720
        //   // createTime:"2022-12-26 18:10:13"
        //   // delFlag:false
        //   // desc:"三生三世"
        //   // id:1002
        //   // itemCode:"1"
        //   // parentId:1101
        //   // updateBy:"不是事有限公司"
        //   // updateById:208720
        //   // updateTime:"2022-12-26 18:10:13"
        //   // url:"http://zxclo

        //   // "amount": amount, // 金额
        //   //   "category": category, // 类目
        //   //   // "createBy": "1",
        //   //   // "createById": 1,
        //   //   // "createTime": "",
        //   //   // "delFlag": true,
        //   //   "desc": dataDec, // 描述
        //   //   // "id": 0,
        //   //   "itemCode": dataNum, // 项目编号
        //   //   "parentId": flowNo, // flowNo
        //   //   // "updateBy": "1",
        //   //   // "updateById": 0,
        //   //   // "updateTime": "1",
        //   //   "url": fileList[0].url // 上传的文件
        //   //#endregion
        // })
        this.data = addArr(taxDeclarationEntVo.details)
      }
    },
    showFileEvent(data, index, btnName, rowNum) {
      console.log('showFileEvent===>', data, index, btnName, rowNum)
      if (btnName == '删除') {
        const tempDataList = (() => {
          return [...this.data[rowNum].dataList]
        })()
        tempDataList.splice(index, 1)
        this.data[rowNum].dataList = tempDataList
        if (tempDataList.length == 0) {
          const ll = [...this.data]
          ll.splice(rowNum, 1)
          this.data = ll
        }
      } else {
        const { dataList } = data
        if (dataList[index] && dataList[index].fileList && dataList[index].fileList.length > 0) {
          // this.AddWatermark.addWatermark(dataList[index].fileList[0].url).then((res) => {
          //   this.PreviewShowConfig.url = res.url
          //   this.PreviewShowConfig.name = res.name
          //   this.PreviewShowConfig.suffix = res.suffix
          //   this.PreviewShowConfig.config.visible = true
          // })
          this.PreviewShowConfig.url = dataList[index].fileList[0].url
          this.PreviewShowConfig.config.visible = true
        }
      }
    },
    modalHidden() {
      this.PreviewShowConfig.config.visible = false
      this.PreviewShowConfig.url = ''
      this.PreviewShowConfig.suffix = ''
      this.PreviewShowConfig.name = ''
    },
    fileChangeEvent(type, fileData) {
      console.log('fileChangeEvent===>', type, fileData)
    },
    handleOk() {
      this.checkRes = [false, false]
      const res = this.$refs['iitd'].getDataCheckRes()
      if (res.indexOf(false) >= 0) {
        this.checkRes[1] = false
      } else {
        this.checkRes[1] = true
      }
      this.fileList = this.$refs['iitd'].getData()
      // console.log('++++=', res, res.indexOf(false) >= 0);
      this.$refs.addIitdForm.handleSubmit()
      // this.winConfig.visible = false
    },
    handleCancel() {
      this.winConfig.visible = false
    },
    addData() {
      // this.itemList.forEach(item=>{
      //   item.value = ''
      // })
      // this.sfzConfig.upLoadCardListConfig[0].fileInfo = { name: '', url: '' }
      // this.sfzConfig.upLoadCardListConfig= []
      this.$nextTick(() => {
        this.winConfig.visible = true
      })
    },
    defaultFormEvent(type, data) {
      console.log('defaultFormEvent==>', type, data, this.checkRes)
      if (type === 'submit' && this.checkRes[1]) {
        const tempDataArr = [...this.data]
        const { name, ...args } = data.values
        let isNot = true
        tempDataArr.forEach((item, index) => {
          if (typeObj[name] === item.name) {
            const size = this.data[index].dataList.length + 1
            tempDataArr[index].dataList.push({
              ...args,
              key: size,
              dataNum: size,
              state: '已上传凭证',
              fileList: this.fileList,
            })
            isNot = false
          }
        })
        // 添加新成员
        if (isNot) {
          tempDataArr.push({
            key: tempDataArr.length + 1,
            name: typeObj[name],
            dataNum: '',
            dataDec: '',
            amount: '',
            dataList: [{ ...args, key: 1, dataNum: 1, state: '已上传凭证', fileList: this.fileList }],
          })
        }
        // console.log('defaultFormEvent 11==>', isNot, tempDataArr);
        this.data = tempDataArr
        this.checkRes[0] = true
        this.checkRes[1] = true
      }
    },
    getSaveData() {
      // 1 业务成本费用；2 业务招待费； 3 职工福利费； 4 工会经费 5 职工教育经费
      // const nameList = { "业务成本费用": '1', "业务招待费": "2", "职工福利费": "3", "工会经费": "4", "职工教育经费": '5' }
      const resArray = []
      const flowNo = this.pageInfo.dbData.flowNo
      this.data.forEach((item) => {
        const { name, dataList } = item
        // {  key: '1',name: 'John Brown1', fileList:[],  dataNum: '1', state:'未上传凭证',  dataDec: '11111111111111', amount:'1' },
        const category = typeObj[name]
        dataList.forEach((dataItem) => {
          const { fileList, dataNum, amount, dataDec } = dataItem
          resArray.push({
            amount: conversionBranch(amount), // 金额
            category: category, // 类目
            // "createBy": "1",
            // "createById": 1,
            // "createTime": "",
            // "delFlag": true,
            desc: dataDec, // 描述
            // "id": 0,
            itemCode: dataNum, // 项目编号
            parentId: flowNo, // flowNo
            // "updateBy": "1",
            // "updateById": 0,
            // "updateTime": "1",
            url: fileList[0].url, // 上传的文件
          })
        })
      })
      return resArray
    },
    saveData() {
      const resList = this.getSaveData()
      // console.log('个税申报上传凭证===>', resList)
      if (resList.length == 0) {
        this.$message.warning('请填写业务支出凭证后再提交！')
        return false
      }
      this.btnLoading = true
      this.btnDisabled = true
      // {details:resList}  []
      getDataForDB('个税申报上传凭证', resList).then((res) => {
        if (res.code == 200) {
          this.$message.success('提交成功')
          this.$router.go(-1)
        } else {
          this.$message.warning(res.message)
        }
        this.btnLoading = false
        this.btnDisabled = false
      })
    },
    btnEvent() {
      const tempState = {
        1: () => {
          // 跳转到收银台
          // this.$message.info('需要跳转收银台')
          const key = "sipiTaxDeclaration"
          Utils.Storage.set(key, { orderNo: [this.pageInfo.dbData.orderNo] })
          this.$router.push({
            path: '/myAccount/accountManage',
            query: {
              po: key
            }
          });
        },
        2: () => {
          //
          this.btnConfig.show = false
          // 全部 5待提交 10待审核 20审核驳回 25资料待完善 26待认证 30待支付 33待退款 40支付失败 50办理中 60办理完成 70已取消 80办理失败
          const param = {...this.pageInfo.dbData}
          param.status = 26
          getDataForDB('个税申报客户确认', param).then(res => {
            if (res.success) {
              this.btnConfig.disabled = true
              this.$message.success(res.message || '数据提交成功')
            } else {
              this.$message.warning(res.message)
            }
          })
        },
        3: () => {
          // this.btnConfig.show = false
          // // this.$message.info('需要调用后台接口 确认线下退税')
          // getDataForDB('税务申报客户确认', this.pageInfo.dbData).then(res => {
          //   if (res.success) {
          //     this.$message.success(res.message || '数据提交成功')
          //   } else {
          //     this.$message.warning(res.message)
          //   }
          // })
        },
        4: () => {
          this.btnConfig.show = false
          const { entId, id } = this.pageInfo.dbData
          // 客户确认 进行短信验证或人脸验证
          // const param = {

          //   "bizCode": 177, // 人脸认证：开票 171 ；退票 172 ； 错票重开 173 ; 税务申报 177
          //   "bizNo": id,
          //   "entId": entId, // 企业id
          //   "type": 3, //认证方式 ：1 人脸 ； 2 短信 ；3 合同签署
          // }
          const param_new = {
            id
          }
          getDataForDB('个税申报客户认证', param_new).then(res => {
            console.log('个税申报客户认证=====>', res);
            if (res.success) {
              // result 、、 result 15910653635
              // this.$message.success(`认证短信已发送至号码为【${res.result}】的手机上，请到此手机上进行认证操作！`)
              this.$message.success(res.result)
            } else {
              this.$message.warning(res.message || '数据请求异常')
            }
          })
        },
      }
      tempState[this.btnConfig.state] && tempState[this.btnConfig.state]()
    },

    /**
     * 本季度纳税总额
     * @param {*} dbData
     */
    setTTPQData(dbData) {
      const apiList = {
        // 查询企业信息及个税申报详情
        178: (dataList) => {
          const {
            details,
            totalRevenue,
            vatReal,
            additionalTaxReal,
            personalTaxReal,
            unbilledRevenue,
            additionalTaxReal2,
            differenceAmount,
          } = dataList || {}
          // this.formGroup[0].tableData.dataSource = addArr(details || [])
          // this.bjdsrhj['detailVal'] = this.fen2yuan(totalRevenue) || '--' // 本值优先使用，当此接口中没有值时去 【本季度申报总额】 中 amount 的值
          // { classification: '税费金额', valueAddedTax: '--', additionalTax: '--', personalTaxReal: '--',additionalTaxReal2:'--',differenceAmount:'--' }
          this.groupData.ttpq.data = [
            {
              classification: '税费金额',
              valueAddedTax: this.fen2yuan(vatReal) || '--',
              additionalTax: this.fen2yuan(additionalTaxReal) || '--',
              personalTaxReal: this.fen2yuan(personalTaxReal) || '--',
              additionalTaxReal2: this.fen2yuan(additionalTaxReal2) || '--',
              differenceAmount: this.fen2yuan(differenceAmount) || '--',
            },
          ]
          // this.groupData.tdaq.data[1].unbilledRevenue = this.fen2yuan(unbilledRevenue)
        },
        // 查询企业信息及个税申报详情177
        177: (dataList) => {
          const {
            details,
            totalRevenue,
            vatReal,
            additionalTaxReal,
            personalTaxReal,
            unbilledRevenue,
            additionalTaxReal2,
            differenceAmount,
          } = dataList || {}
          // this.formGroup[0].tableData.dataSource = addArr(details || [])
          // this.bjdsrhj['detailVal'] = this.fen2yuan(totalRevenue) || '--' // 本值优先使用，当此接口中没有值时去 【本季度申报总额】 中 amount 的值
          // { classification: '税费金额', valueAddedTax: '--', additionalTax: '--', personalBusinessIncomeTax: '--' }
          this.groupData.ttpq.data = [
            {
              classification: '税费金额',
              valueAddedTax: this.fen2yuan(vatReal) || '--',
              additionalTax: this.fen2yuan(additionalTaxReal) || '--',
              personalTaxReal: this.fen2yuan(personalTaxReal) || '--',
              additionalTaxReal2: this.fen2yuan(additionalTaxReal2) || '--',
              differenceAmount: this.fen2yuan(differenceAmount) || '--',
            },
          ]

          // this.groupData.tdaq.data[1].unbilledRevenue = this.fen2yuan(unbilledRevenue)
        },
      }
      return apiList[this.pageType](dbData)
    },

    /**
     * 用于请求接口
     * @param {*} key
     * @param {*} param
     * @param {*} backFun 数据处理的回调方法
     */
    async pageGetDataForDB(key, param, backFun) {
      const res = await getDataForDB1(key, param)
      const { success, message, result } = res
      if (success) {
        // this.dbDataList[this.pageType][key] = result
        backFun(result)
      } else {
        console.error(key, param)
        this.$message.warning(message || `接口请求失败:${key}`)
      }
    },
    /**
     * 获取接口对应的参数
     * @param {*} urlName
     */
    getParam(urlName, flowNo) {
      const smsbizNo = flowNo // this.pageInfo.dbData.flowNo
      const apiList = {
        178: {
          本季度申报总额: () => {
            return { id: smsbizNo }
          },
        },
        177: {
          本季度申报总额177: () => {
            return { id: smsbizNo }
          },
        },
      }
      return apiList[this.pageType][urlName]()
    },
    /**
     * 获取接口返回结果对应的处理方法
     * @param {*} urlName
     */
    getbackFun(urlName) {
      const apiList = {
        178: {
          查询企业信息及个税申报详情: (dataList) => {
            const { details, totalRevenue, vatReal, additionalTaxReal, personalTaxReal, unbilledRevenue } =
              dataList || {}
            // this.formGroup[0].tableData.dataSource = addArr(details || [])
            // this.bjdsrhj['detailVal'] = this.fen2yuan(totalRevenue) || '--' // 本值优先使用，当此接口中没有值时去 【本季度申报总额】 中 amount 的值
            // { classification: '税费金额', valueAddedTax: '--', additionalTax: '--', personalBusinessIncomeTax: '--' }
            this.groupData.ttpq.data = [
              {
                classification: '税费金额',
                valueAddedTax: this.fen2yuan(vatReal) || '--',
                additionalTax: this.fen2yuan(additionalTaxReal) || '--',
                personalBusinessIncomeTax: this.fen2yuan(personalTaxReal) || '--',
              },
            ]

            this.groupData.tdaq.data[1].unbilledRevenue = this.fen2yuan(unbilledRevenue)
          },
          本季度申报总额: (dataList) => {
            const tempData = [
              // { name: '税率', VATInvoice: '--%', VATInvoice1: '--%', VATGeneralInvoice: '1%', unbilledRevenue: '1%' },
              // { name: '收入金额', VATInvoice: '--', VATInvoice1: '--', VATGeneralInvoice: '654', unbilledRevenue: '' },
              {
                classification: '税率',
                ValueAddedTaxInvoice: '--',
                ValueAddedTaxInvoice1: '--',
                VATGeneralInvoice: '--',
                unbilledRevenue: '1%',
              },
              {
                classification: '收入金额',
                ValueAddedTaxInvoice: '--',
                ValueAddedTaxInvoice1: '--',
                VATGeneralInvoice: '--',
                unbilledRevenue: '',
              },
            ]
            const { details, amount, universalTicketAmount, universalTicketRate } = dataList || {}

            // this.bjdsrhj['selfVal'] = this.fen2yuan(amount) || '--'
            tempData[0].VATGeneralInvoice = universalTicketRate && (Number(universalTicketRate) * 100) +'%' || '--'
            tempData[1].VATGeneralInvoice = this.fen2yuan(universalTicketAmount) || '--'
            details &&
              details.forEach((item, index) => {
                const { specialTicketRate, specialTicketAmount } = item
                const keyList = { 0: 'ValueAddedTaxInvoice', 1: 'ValueAddedTaxInvoice1' }
                if (keyList[index]) {
                  tempData[0][keyList[index]] = specialTicketRate && (Number(specialTicketRate) * 100) +"%"|| '--'
                  tempData[1][keyList[index]] = this.fen2yuan(specialTicketAmount) || '--'
                }
              })
              console.log('@@@@@@@@@@@@@@@',dataList,details, tempData);
            this.groupData.tdaq.data = tempData
            this.groupData.tdaqSum = this.fen2yuan(amount).toFixed(2) || ''
          },
          客户确认未开票收入: (dataList) => {},
        },
        177: {
          查询企业信息及个税申报详情177: (dataList) => {
            const { details, totalRevenue, vatReal, additionalTaxReal, personalTaxReal, unbilledRevenue } =
              dataList || {}
            // this.formGroup[0].tableData.dataSource = addArr(details || [])
            // this.bjdsrhj['detailVal'] = this.fen2yuan(totalRevenue) || '--' // 本值优先使用，当此接口中没有值时去 【本季度申报总额】 中 amount 的值
            // { classification: '税费金额', valueAddedTax: '--', additionalTax: '--', personalBusinessIncomeTax: '--' }
            this.groupData.ttpq.data = [
              {
                classification: '税费金额',
                valueAddedTax: this.fen2yuan(vatReal) || '--',
                additionalTax: this.fen2yuan(additionalTaxReal) || '--',
                personalBusinessIncomeTax: this.fen2yuan(personalTaxReal) || '--',
              },
            ]

            this.groupData.tdaq.data[1].unbilledRevenue = this.fen2yuan(unbilledRevenue)
          },
          本季度申报总额177: (dataList) => {
            const tempData = [
              // { name: '税率', VATInvoice: '--%', VATInvoice1: '--%', VATGeneralInvoice: '1%', unbilledRevenue: '1%' },
              // { name: '收入金额', VATInvoice: '--', VATInvoice1: '--', VATGeneralInvoice: '654', unbilledRevenue: '' },
              {
                classification: '税率',
                ValueAddedTaxInvoice: '--%',
                ValueAddedTaxInvoice1: '--%',
                VATGeneralInvoice: '1%',
                unbilledRevenue: '1%',
              },
              {
                classification: '收入金额',
                ValueAddedTaxInvoice: '--',
                ValueAddedTaxInvoice1: '--',
                VATGeneralInvoice: '654',
                unbilledRevenue: '',
              },
            ]
            const { details, amount, universalTicketAmount, universalTicketRate } = dataList || {}
            // this.bjdsrhj['selfVal'] = this.fen2yuan(amount) || '--'
            tempData[0].VATGeneralInvoice = universalTicketRate && (Number(universalTicketRate) * 100) +'%' || '--'
            tempData[1].VATGeneralInvoice = this.fen2yuan(universalTicketAmount) || '--'
            details &&
              details.forEach((item, index) => {
                const { specialTicketRate, specialTicketAmount } = item
                const keyList = { 0: 'ValueAddedTaxInvoice', 1: 'ValueAddedTaxInvoice1' }
                if (keyList[index]) {
                  tempData[0][keyList[index]] = specialTicketRate && (Number(specialTicketRate) * 100) +"%"|| '--'
                  tempData[1][keyList[index]] = this.fen2yuan(specialTicketAmount) || '--'
                }
              })

            this.groupData.tdaq.data = tempData
            this.groupData.tdaqSum = this.fen2yuan(amount).toFixed(2) || ''
          },
        },
      }
      return apiList[this.pageType][urlName]
    },
    /**
     * 设置本季度申报总额
     */
    getPageDataForAPI(flowNo) {
      const getApiList = this.apiList[this.pageType]
      getApiList.forEach((apiName, index) => {
        const param = this.getParam(apiName, flowNo)
        const backFun = this.getbackFun(apiName)
        this.pageGetDataForDB(apiName, param, backFun)
      })
    },
  },
}
</script>

<style lang="less">
.iitd-con {
  .iitd-title {
    font-size: 20px;
    font-family: PingFangSC-Semibold, PingFang SC;
    font-weight: 600;
    color: #333333;
  }

  .iitd-list {
    display: flex;
    justify-content: flex-start;
    align-items: center;
    flex-direction: column;

    .iitd-item {
      width: 100%;

      .ant-table-thead > tr > th,
      .ant-table-tbody > tr > td {
        padding: 8px 0;
      }

      .column-title {
        text-align: center;
      }

      .ant-table-footer {
        padding: 0;
      }

      .table-row {
        display: flex;
        justify-content: flex-start;
        align-items: center;
        height: 34px;

        .table-cell {
          flex: 1;
          height: 100%;
          display: flex;
          justify-content: center;
          align-items: center;
        }
      }

      &.group {
        .group-title {
          font-size: 20px;
          font-family: PingFangSC-Semibold, PingFang SC;
          font-weight: 600;
          color: #333333;
          border-bottom: 1px solid rgb(235, 238, 245);
          padding: 10px 0;
          margin: 10px 0;
        }

        .group-table {
          .ant-pagination {
            display: none;
          }

          margin: 20px 0;

          .ant-table-title {
            display: flex;
            justify-content: center;
            align-items: center;
            font-weight: 600;
          }
        }

        .itd-con {
          margin: 10px 0;
        }
      }
    }
  }
}

.winModal {
  .ant-modal-title {
    text-align: left;
  }

  .winModal-body {
    padding: 10px 30px;

    .file-con {
      .xx:before {
        display: inline-block;
        margin-right: 4px;
        color: #f5222d;
        font-size: 14px;
        font-family: SimSun, sans-serif;
        line-height: 1;
        content: '*';
      }
    }
  }
}
</style>
